package com.common.result;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/9/29 14:49
 */
@Configuration
@ConditionalOnClass(WebMvcConfigurer.class)
public class ResponseAutoConfiguration implements WebMvcConfigurer {

    @Bean
    public ResponseAdvice responseBodyAdvice(){
        return new ResponseAdvice();
    }

    /**
     * 避免返回String类型时,优先选择StringHttpMessageConverter的问题。
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(0, new MappingJackson2HttpMessageConverter());
    }
}
